package com.myopen.controller.admin;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.core.ActionKey;
import com.myopen.base.BaseController;
import com.myopen.base.BaseVo;
import com.myopen.config.ConstConfig;
import com.myopen.model.Config;

public class ConfigController extends BaseController{

	@ActionKey("/admin/config")
	public void config(){
		
		Map<String,Object> website=Config.dao.getValueToMap(ConstConfig.SYSTEM_CONFIG);
		if(website==null) {
			website=new HashMap<>();
		}
		
		setAttr("vo", website);
		render("/admin/config/index.html");
		
	}
	
	@ActionKey("/admin/config/save")
	public void myWebsiteSave(){
		
		BaseVo baseVo=new BaseVo();
		
		Map<String,Object> website=Config.dao.getValueToMap(ConstConfig.SYSTEM_CONFIG);
		
		website.put("cms_name", getPara("cms_name"));

		website.put("smtp_name", getPara("smtp_name"));
		website.put("smtp_email", getPara("smtp_email"));
		website.put("smtp_password", getPara("smtp_password"));
		website.put("smtp_host", getPara("smtp_host"));
		website.put("smtp_port", getPara("smtp_port"));
		website.put("smtp_way", getPara("smtp_way"));
		
		Config.dao.saveMap(ConstConfig.SYSTEM_CONFIG,website);
		
		baseVo.setCode("0");
		
		renderJson(baseVo);
	}
	
	
}
